package com.zzzyh.forumsystemclient.cotroller;

import com.zzzyh.forumsystemclient.common.AppResult;
import com.zzzyh.forumsystemclient.model.Notice;
import com.zzzyh.forumsystemclient.services.INoticeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/api")
public class NoticeController {
    @Autowired
    private INoticeService noticeService;
    @RequestMapping("getNotice")
    public AppResult<Map<String, List<Notice>>> getNotice(){
        Map<String, List<Notice>> data = new HashMap<>();
        List<Notice> top = new ArrayList<>();
        List<Notice> right = new ArrayList<>();
        noticeService.getNotice().forEach(notice -> {
            if(notice.getPosition().equals("top")){
                top.add(notice);
            }else if(notice.getPosition().equals("right")){
                right.add(notice);
            }else{

            }
        });
        data.put("top", top);
        data.put("right", right);

        return AppResult.success(data);
    }
}
